package com.cndcare.msc.util;

import com.cndcare.msc.client.WxTemplateMsgClient;
import com.cndcare.msc.config.SystemConfig;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class WxUtils {

    @Autowired
    private WxTemplateMsgClient wxTemplateMsgClient;
    @Autowired
    private SystemConfig systemConfig;

    public void 医院通知(
            String openId, String first, String keyword1, String keyword2, String remark, String url
    ) {
        /**
         * 医院通知
         * gUk_UUENjtJYUTTqsZR7QcWissMKJ6hlCagQUZNnGfk
         * {{first.DATA}}
         * 通知时间：{{keyword1.DATA}}
         * 通知内容：{{keyword2.DATA}}
         * {{remark.DATA}}
         */
        new Thread(() -> {
            WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
                    .toUser(openId)
                    .url(url)
                    .templateId("gUk_UUENjtJYUTTqsZR7QcWissMKJ6hlCagQUZNnGfk")
                    .build();

            templateMessage.addData(new WxMpTemplateData("first", first, "#808080"));
            templateMessage.addData(new WxMpTemplateData("keyword1", keyword1, "#000000"));
            templateMessage.addData(new WxMpTemplateData("keyword2", keyword2, "#000000"));
            if (StringUtils.isNotEmpty(remark)) {
                templateMessage.addData(new WxMpTemplateData("remark", remark, "#fe0505"));
            }

            wxTemplateMsgClient.sendTemplateMsg(systemConfig.getAppId(), templateMessage);
        }).start();
    }

}
